From 2c1274f612a1c9fc276c7af8146b073392c49ea7 Mon Sep 17 00:00:00 2001 From: Kalita Alexey Date: Sat, 11 Feb 2017 11:21:02 +0300 Subject: [PATCH] Fixed a breaking change and added tests for that case. --- src/cargo/core/manifest.rs | 19 +++++++------ tests/metadata.rs | 58 +++++++++++++++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 9 deletions(-) diff --git a/src/cargo/core/manifest.rs b/src/cargo/core/manifest.rs index 3f95edee4..d17b787fe 100644 --- a/src/cargo/core/manifest.rs +++ b/src/cargo/core/manifest.rs @@ -113,18 +113,21 @@ pub enum TargetKind { } impl TargetKind { - pub fn name(&self) -> &'static str { + /// Returns a vector of crate types as specified in a manifest with one difference. + /// For ExampleLib it returns "example" instead of crate types + pub fn kinds(&self) -> Vec<&str> { use self::TargetKind::*; match *self { - Lib(_) => "lib", - Bin => "bin", - ExampleBin | ExampleLib(_) => "example", - Test => "test", - CustomBuild => "custom-build", - Bench => "bench" + Lib(ref kinds) => kinds.iter().map(LibKind::crate_type).collect(), + Bin => vec!["bin"], + ExampleBin | ExampleLib(_) => vec!["example"], + Test => vec!["test"], + CustomBuild => vec!["custom-build"], + Bench => vec!["bench"] } } + /// Returns a vector of crate types as specified in a manifest pub fn crate_types(&self) -> Vec<&str> { use self::TargetKind::*; match *self { @@ -216,7 +219,7 @@ struct SerializedTarget<'a> { impl Encodable for Target { fn encode(&self, s: &mut S) -> Result<(), S::Error> { SerializedTarget { - kind: vec![self.kind.name()], + kind: self.kind.kinds(), crate_types: self.kind.crate_types(), name: &self.name, src_path: &self.src_path.display().to_string(), diff --git a/tests/metadata.rs b/tests/metadata.rs index 07dc4bbec..f7dbbc414 100644 --- a/tests/metadata.rs +++ b/tests/metadata.rs @@ -53,6 +53,62 @@ fn cargo_metadata_simple() { }"#)); } +#[test] +fn library_with_several_crate_types() { + let p = project("foo") + .file("src/lib.rs", "") + .file("Cargo.toml", r#" +[package] +name = "foo" +version = "0.5.0" + +[lib] +crate-type = ["lib", "staticlib"] + "#); + + assert_that(p.cargo_process("metadata"), execs().with_json(r#" + { + "packages": [ + { + "name": "foo", + "version": "0.5.0", + "id": "foo[..]", + "source": null, + "dependencies": [], + "license": null, + "license_file": null, + "description": null, + "targets": [ + { + "kind": [ + "lib", + "staticlib" + ], + "crate_types": [ + "lib", + "staticlib" + ], + "name": "foo", + "src_path": "[..][/]foo[/]src[/]lib.rs" + } + ], + "features": {}, + "manifest_path": "[..]Cargo.toml" + } + ], + "workspace_members": ["foo 0.5.0 (path+file:[..]foo)"], + "resolve": { + "nodes": [ + { + "dependencies": [], + "id": "foo 0.5.0 (path+file:[..]foo)" + } + ], + "root": "foo 0.5.0 (path+file:[..]foo)" + }, + "version": 1 + }"#)); +} #[test] fn cargo_metadata_with_deps_and_version() { @@ -567,7 +623,7 @@ fn cargo_metadata_no_deps_cwd() { } #[test] -fn carg_metadata_bad_version() { +fn cargo_metadata_bad_version() { let p = project("foo") .file("Cargo.toml", &basic_bin_manifest("foo")) .file("src/foo.rs", &main_file(r#""i am foo""#, &[])); -- 2.30.2